package com.orange.core.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>ClassName:RegistrationStatus</p>
 * <p>Description: 报名表枚举</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/6/4 18:22</p>
 */
@AllArgsConstructor
@Getter
public enum RegistrationEnum implements Serializable {

    /**
     * 待确认
     */
    PENDING(0, "待确认"),

    /**
     * 已确认
     */
    CONFIRMED(1, "已确认"),

    /**
     * 已取消
     */
    CANCELLED(2, "已取消");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    private static final Map<Integer, RegistrationEnum> CODE_TO_MENUM_MAP = Arrays.stream(values())
            .collect(Collectors.toUnmodifiableMap(RegistrationEnum::getCode, e -> e));

    public  static RegistrationEnum getByCode(Integer code) {
        RegistrationEnum registrationEnum = CODE_TO_MENUM_MAP.get(code);
        if (registrationEnum == null) {
            throw new IllegalArgumentException("无效的code值：" + code);
        }
        return registrationEnum;
    }

}
